home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fritz: All Fritz
/
All Fritz.zip
/
All Fritz
/
FILES
/
BUSINESS
/
STATA3.LZH
/
PROBIT.TUT
< prev
next >
Wrap
Text File
|
1988-08-30
|
12KB
|
335 lines
set output error
set display page 23
set more 1
#delimit ;
di _n(5) in wh
" ___ ____ ____ ____ ____ tm" _n
" /__ / ____/ / ____/" _n
"___/ / /___/ / /___/ Maximum-Likelihood Probit and Logit Estimation"
_n
"------------------------------------------------------------------------------"
_n(2) ;
di in gr
"This tutorial provides an overview of the Stata commands for estimating" _n
"models of qualitative dependent variables using maximum-likelihood techniques."
_n
"The commands we will discuss are:" _n(2)
_col(16) in wh "inspect probit logit" _n(2)
in gr
"We begin by using some automobile data we previously entered into Stata and"
_n
"stored as auto.dta. That data set contains a number of variables, but we will"
_n
"keep only those we need." _n(4) ;
#delimit cr
mac def path
capture run nullfile.tut
if _rc {
mac def path "\stata\"
capture run %path`nullfile.tut
if _rc {
mac def path "/usr/stata/"
capture run %path`nullfile.tut
if _rc {
#delimit ;
di in red
"I cannot find the other tutorial files. I have looked in the current" _n
"directory and in \stata (DOS) or /usr/stata (Unix). Is Stata installed" _n
"correctly?" _n(2)
"In any case, I cannot run the tutorial." ;
#delimit cr
exit
}
}
}
macro define F5 "do %path`contents.tut;"
macro define F6 "do %path`probit.tut;"
#delimit ;
di in wh ". use %path`auto, clear" ;
noisily use %path`auto, clear ;
di _n in wh ". keep make foreign mpg weight" ;
keep make foreign mpg weight ;
set more 0 ; more ; set more 1 ;
di _n in wh ". describe" ;
noisily describe ;
di _n in wh ". list in 1/9" ;
noisily list in 1/9 ;
set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n in gr
"Probit and logit are used for analysis of qualitative dependent variables." _n
"We have chosen to look at whether a car is foreign or domestic. In our data,"
_n
"the variable 'foreign' equals 1 when a car is foreign and 0 when domestic." _n
"Let's " in wh "inspect" in gr " this variable:" _n
in wh _dup(79) "-" _n(2)
". inspect foreign" ;
noisily inspect foreign ;
set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n in gr
"All of Stata's estimation commands share the same syntax: The name of the" _n
"estimator is followed by the left-hand-side variable which in turn is fol-" _n
"lowed by each of the right-hand-side variables. Thus, the syntax for logit" _n
"estimation is:" _n(2)
_col(16) in wh "logit" in gr " lhs_variable rhs_variables ..." _n(2)
in gr
"In the case of both probit and logit, the lhs_variable should take on the" _n
"values 0 and 1; estimation proceeds by nonlinear maximum-likelihood tech-" _n
"niques." _n(2)
"We are going to estimate a model that predicts whether a car is foreign. The"
_n
"determinants of our model are the car's weight and gas mileage rating, so we"
_n
"will type:" _n
in wh _dup(79) "-" _n(8)
". logit foreign weight mpg" ;
set more 0 ; more ; set more 1 ;
noisily logit foreign weight mpg ;
di ; set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n in gr
"Stata's estimation commands share another handy feature: If you retype the" _n
"name of the command, they reshow the results of the last estimation." _n
in wh _dup(79) "-" _n(3)
". logit" ;
noisily logit ;
di _n(2) ; set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n in gr
"Being able to reshow results is handy when numbers have scrolled off the" _n
"screen. It also allows you to specify different options that you forgot" _n
"to request when you estimated the model." _n(2)
"Both the "
in wh "probit" in gr " and " in wh "logit"
in gr " commands can produce a table comparing the actual" _n
"outcome with whether the predicted probability is greater than or less than" _n
"0.5. We request that table below, and tell Stata not to bother with redis-" _n
"playing the coefficient table:" _n
in wh _dup(79) "-" _n(3)
". logit, tabulate nocoef" ;
noisily logit, tabulate nocoef ;
set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n in gr
"We estimated a model of foreign on weight and mpg using "
in wh "logit" in gr ". We could just" _n
"as easily have estimated the model using "
in wh "probit" in gr ". We type:" _n
in wh _dup(79) "-" _n(20)
". probit foreign weight mpg" ;
set more 0 ; more ; set more 1 ;
noisily probit foreign weight mpg ;
di ; set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n in gr
"Both probit and logit are nonlinear estimators that are obtained by iterative"
_n
"techniques. Stata provides three options to control convergence:" _n(2)
_col(15) in wh "iterate(" in gr "#" in wh ")"
_col(31) in gr "the maximum number of iterations" _n
_col(15) in wh "tolerance(" in gr "#" in wh ")"
_col(31) in gr "the coefficient tolerance" _n
_col(15) in wh "ltolerance(" in gr "#" in wh ")"
_col(31) in gr "the log-likelihood tolerance" _n(2)
"You never have to specify any of these option, but you can if you wish. If" _n
"you do specify one or more of these options, you bear responsibility for the"
_n
"accuracy of the final results." _n
in wh _dup(79) "-" _n(11) ;
set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n in gr
"Once you've produced probit or logit estimates, you can obtain the predicted"
_n
"probabilities using the " in wh "predict" in gr " command." _n(2)
"We will illustrate "
in wh "predict" in gr " using the same data on which we estimated the" _n
"equation, although "
in wh "predict" in gr " has no such restrictions. You can just as easily"
_n
"turn to another data set and make predictions based on your model." _n(2)
"The syntax of " in wh "predict" in gr" is:" _n(2)
_col(16) in wh "predict" in gr " new-variable-name" _n(2)
"After probit or logit estimation, "
in wh "predict" in gr " predicts probabilities. After re-"
_n
"gression or ANOVA estimation, " in wh "predict" in gr " predicts outcomes." _n
in wh _dup(79) "-" _n(2)
". predict probhat" ;
predict probhat ;
di _n in wh ". summarize probhat" ;
noisily summarize probhat ;
set more 0 ; more ; set more 1 ;
di _n in wh ". list in 1/13" ;
noisily list in 1/13 ;
set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n
"predict" in gr
" can also calculate the predicted value of the index function. In" _n
"the case of "
in wh "probit" in gr ", the predicted probabilities are given by" _n(2)
_col(26) "probhat = F(zhat)" _n(2)
"where F() is the cumulative normal distribution. To request the predicted" _n
"values of the index function, the syntax is:" _n(2)
_col(16) in wh "predict"
in gr " new-variable-name" in wh ", index" _n(2)
in wh _dup(79) "-" _n(4)
". predict zhat, index" ;
predict zhat, index ;
di _n in wh ". summarize probhat zhat" ;
noisily summarize probhat zhat ;
di ; set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n in gr
"Stata's "
in wh "probit" in gr " and " in wh "logit" in gr
" commands are fully integrated with all the features" _n
"of Stata. After a regression or ANOVA model, typing '"
in wh "correlate, _coef" in gr "' shows" _n
"the covariance matrix of the estimators (as a correlation matrix). After" _n
in wh "probit" in gr " and " in wh "logit"
in gr ", the calculation is based on the information matrix." _n
in wh _dup(79) "-" _n(12)
". correlate, _coef" ;
noisily correlate, _coef ;
set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n in gr
"After regression or ANOVA estimation, typing '"
in wh "correlate, _coef covariance" in gr "'" _n
"shows the covariance matrix of the estimators. After probit or logit estima-"
_n
"tion, it shows the inverse information matrix. Of course, you can abbreviate."
_n
in wh _dup(79) "-" _n(12)
". cor, _c cov" ;
noisily cor, _c cov ;
set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n in gr
"Stata is willing to perform hypotheses tests based on the information matrix"
_n
"just as it is after regression or ANOVA estimation. The syntax for "
in wh "test" in gr " is:"
_n(2)
_col(16) in wh "test" in gr " expression " in wh "=" in gr " expression" _n(2)
"Stata will perform algebra to simplify the expression. For example, here's" _n
"a crazy hypothesis that illustrates Stata's capabilities:" _n
in wh _dup(79) "-" _n(9)
". test (weight-mpg)/2 - (mpg-weight) = mpg - (weight+mpg)*2" ;
noisily test (weight-mpg)/2 - (mpg-weight) = mpg - (weight+mpg)*2 ;
set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n
"test" in gr "'s " in wh "accumulate" in gr
" option allows you to add additional tests so that you can" _n
"specify joint hypotheses. Adding to our crazy test the hypothesis that" _n
"'mpg=0', we obtain:" _n
in wh _dup(79) "-" _n(2)
". test mpg=0, accumulate" ;
noisily test mpg=0, accum ;
set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n in gr
"All of Stata's other features work with "
in wh "probit" in gr " and " in wh "logit" in gr " as well. Suppose" _n
"you wanted to estimate the model on only cars that yield more than 18 miles" _n
"per gallon. You do not have to form a separate data set. You type"
_n(2)
_col(16) in wh "probit foreign weight mpg if mpg>18" _n(2)
in gr "if you wanted probit estimates, or" _n(2)
_col(17) in wh "logit foreign weight mpg if mpg>18" _n(2)
in gr "to obtain logit estimates." _n
in wh _dup(79) "-" _n(11)
". probit foreign weight mpg if mpg>18" ;
set more 0 ; more ; set more 1 ;
noisily probit foreign weight mpg if mpg>18 ;
di ; set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n
"probit" in gr " and " in wh "logit" in gr
" have one more feature, and it is probably the most useful."
_n(2)
"Have you ever estimated a model where one or more of the independent variables"
_n
"perfectly predict success or failure? If you have, you've experienced one of"
_n
"the more unpleasant aspects of computer optimization. The program begins" _n
"iterating and iterating as it trys to make one or more of the coefficients" _n
"equal to infinity. Finally, if the program ever stops at all, it produces" _n
"results that are nothing more than numerical roundoff error." _n(2)
"Stata watches for these kinds of problems, alerts you, fixes them, and pro-"
_n
"perly estimates the model." _n ;
di in gr
"Right now, this tutorial is concocting such a problem." _n
in wh _dup(79) "-" _n(8) ;
use %path`auto, clear ;
keep make mpg rep78 foreign ;
drop if rep78==. ;
gen int repair=1 if rep78==1 | rep78==2 ;
replace repair=2 if rep78==3 | rep78==4 ;
replace repair=3 if rep78==4 ;
tab repair, gen(repair) nofreq ;
drop rep78 ;
di in wh ". tabulate foreign repair" ;
set more 0 ; more ; set more 1 ;
noisily tabulate foreign repair ;
di in wh _dup(79) "-" _n in gr
"This is our familiar automobile data. We added a variable called repair that"
_n
"takes on the values 1, 2, and 3, reflecting the repair record of our cars;" _n
"1 means poor, 2 average, and 3 better-than-average." _n(2)
"In our data, cars that have poor repair records are solely domestic, although"
_n
"other domestic cars have average and better-than-average records, too. If we"
_n
"were to predict foreign manufacture on the basis of repair records, the pre-"
_n
"dicted probability for repair==1 would be zero, meaning the probit or logit" _n
"coefficient would be minus infinity. This would set most computer programs"
_n
"buzzing. Let's try Stata:" _n
in wh _dup(79) "-" _n(2)
". probit foreign repair1 repair2" ;
set more 0 ; more ; set more 1 ;
noisily probit foreign repair1 repair2 ;
di ; set more 0 ; more ; set more 1 ;
drop _all ;
label drop _all ;
macro define F6 "do %path`survive.tut;" ;
di _n(4) in white
"Demonstration ends" _n
"------------------" _n ;
di in green
"That concludes our short demonstration, but there's much more. We now return"
_n
"control to you. Some suggestions:" _n ;
di in green
"If you ..." _col(34) "Then we will show you ..." _n
" Press " in white "F5" in green _col(38) "a table of tutorial contents" _n
" Press " in white "F6" in green _col(38) "the next tutorial, "
in white "survive.tut" _n ;
run %path`tobuy.tut ;